import { Behaviour, GameObject, getGameObjectById, core } from "../gameengine";
import { ColliderSystem } from "../rect/ColliderSystem";
import { RectCollider, RectColliderType } from "../rect/RectCollider";
import { user } from "../user";
import { dcrPrefab1, dcrPrefab2 } from "../data";




export class daocaoren1 extends Behaviour {
    ui1: GameObject;
    ui2: GameObject;


    protected onStart() {

    }

    protected onUpdate(advancedTime: number) {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        const collider = this.displayObject.getScript(RectCollider);
        const nextCollider = {
            left: collider.left + -4,
            right: collider.right + 4,
            top: collider.top + -4,
            bottom: collider.bottom + 4
        }
        const hitTestResult1 = colliderSystem.check(nextCollider, RectColliderType.MAINROLE);
        if (hitTestResult1) {
            if (!user.getCao) {
                if (!this.ui1) {
                    this.ui1 = core.createPrefab(dcrPrefab1);
                    const scene = getGameObjectById("UIScene");
                    scene.addChild(this.ui1);
                }
            }
            if (user.getCao) {
                if (!this.ui2) {
                    user.removerock = true;
                    this.ui2 = core.createPrefab(dcrPrefab2);
                    const scene = getGameObjectById("UIScene");
                    scene.addChild(this.ui2);
                }
            }
        }

    }


}